package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.StoneTypeMapper;
import com.gxa.zhonglong.pojo.StoneType;
import com.gxa.zhonglong.service.StoneTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author NITRO
 */

@Service("stoneTypeService")
@Transactional(rollbackFor = {Throwable.class})
public class StoneTypeServiceImpl implements StoneTypeService {

    @Autowired
    private StoneTypeMapper stoneTypeMapper;


    @Override
    public Boolean addStoneType(StoneType stoneType) throws BusinessException {
        StoneType stoneType1 = stoneTypeMapper.selectStoneTypeByCode(stoneType.getTypeCode());
        if (stoneType1 == null) {
           stoneTypeMapper.addStoneType(stoneType);
            return true;
        }
        throw  new BusinessException(ExceptionCode.ADD_DEFEATED);
    }

    @Override
    public void deleteStoneType(List<Long> ids) throws BusinessException {
        if(stoneTypeMapper.deleteStoneType(ids)<1){
            throw new BusinessException(ExceptionCode.DELETE_FALSE);
        }
    }

    @Override
    public Boolean updateStoneType(StoneType stoneType) throws BusinessException {
        Boolean aBoolean = stoneTypeMapper.updateStoneType(stoneType);
        if (aBoolean) {
            return true;
        }
        throw  new BusinessException(ExceptionCode.UPDATE_FALSE);
    }

    @Override
    public List<StoneType> getStoneTypeList() {
        List<StoneType> stoneTypes = stoneTypeMapper.selectStoneType();
        return stoneTypes;
    }
}
